package cn.niit.letuseatdemo.entity.vo.response;


import cn.niit.letuseatdemo.common.enums.ExceptionCodeEnum;
import cn.niit.letuseatdemo.entity.vo.response.PageVO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@NoArgsConstructor
public class BaseResponse<T> {

    private String resCode = "200";

    private String resDesc = "请求成功";

    private PageVO pageParam;

    private T data;

    public BaseResponse(T data){
        this.data = data;
    }

    public BaseResponse(String resDesc) {
        this.resDesc = resDesc;
    }

    public BaseResponse(String resCode, String resDesc) {
        this.resCode = resCode;
        this.resDesc = resDesc;
    }


    /*
    * @Description:成功，默认没有其他数据，只是状态。
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/12/7 17:51
     * @return: cn.niit.letuseatdemo.entity.vo.response.BaseResponse
    **/
    public static BaseResponse success(){
        return new BaseResponse("请求成功!");
    }

    /*
    * @Description: 成功：包含响应数据
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/12/7 17:50
     * @param: data
     * @return: cn.niit.letuseatdemo.entity.vo.response.BaseResponse
    **/
    public static BaseResponse success(Object data){
        return new BaseResponse(data);
    }


    /*
    * @Description: 返回错误信息
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/12/7 17:50
     * @param: resCode
     * @param: resDesc
     * @return: cn.niit.letuseatdemo.entity.vo.response.BaseResponse
    **/
    public static BaseResponse error(String resCode, String resDesc){
        return new BaseResponse(resCode, resDesc);
    }


    /*
    * @Description: 返回错误信息
    * @Author: Zhang Shiqi
    * @CreateTime： 2022/12/7 17:50
     * @param: code
     * @return: cn.niit.letuseatdemo.entity.vo.response.BaseResponse
    **/
    public static BaseResponse error(ExceptionCodeEnum code) {
        return new BaseResponse(code.getResCode(), code.getResDesc());
    }
}